package bogus.settings;


import java.awt.Rectangle;

import owg.shallowserializer.ShallowSerializer;
import owg.shallowserializer.ShallowSerializer.Comment;
import owg.util.AdditionalParsers;
import world.Global;
import bogus.main.BogusMkII;

public class Settings
{
    static ShallowSerializer<Settings> serializer = new ShallowSerializer<Settings>(Settings.class);
    static
    {
    	AdditionalParsers.register();
    }

    @Comment("The bounds of the game window, when in windowed mode.")
    public Rectangle windowedBounds =  null;
    @Comment("Whether the game should run in fullscreen mode.")
    public boolean isFullscreen = true;
    @Comment("Whether only power-of-two textures should be used(compatibility).")
    public boolean forcePOTS = false;
    @Comment("How large the audio buffer should be(only when useOpenAL is false). Causes latency, but reduces glitches.")
    public int jsAudioBufferMultiplier = 8;
    @Comment("Whether to use OpenAL(performance). Set to false to use JavaSound(compatibility).")
    public boolean useOpenAL = false;
    @Comment("Whether to synchronize frame rate with vertical blanks to avoid tearing of the image. Reduces maximum potential frame rate.")
    public boolean verticalSync = false; 

    public static Settings settings;

    private void copyFromProgram()
    {
	windowedBounds = BogusMkII.frame.getWindowedBounds();
	isFullscreen = BogusMkII.frame.isFullscreen();
    }

    public static Settings open()
    {
	return serializer.read(Global.SETTINGS.getAbsolutePath());
    }

    public void save()
    {
	copyFromProgram();
	serializer.write(Global.SETTINGS.getAbsolutePath(), this);
    }
}
